package http.aio;

import java.nio.ByteBuffer;
import java.nio.channels.AsynchronousServerSocketChannel;
import java.nio.channels.AsynchronousSocketChannel;
import java.nio.channels.CompletionHandler;

/**
 * @author fengbo
 * @version 1.0.0
 * @date 2018/12/5 15:03
 * @since JDK 1.8
 */
public class AcceptHandler implements CompletionHandler<AsynchronousSocketChannel, AsynchronousServerSocketChannel> {

    @Override
    public void completed(AsynchronousSocketChannel channel, AsynchronousServerSocketChannel attachment) {
        ByteBuffer buf = ByteBuffer.allocate(1024);
        channel.read(buf, buf, new ReadHandler(channel));
        attachment.accept(attachment, this);
    }

    @Override
    public void failed(Throwable exc, AsynchronousServerSocketChannel attachment) {
    }
}
